package com.aurora.oa.work.presenter;


import com.aurora.oa.bean.HttpResult;
import com.aurora.oa.listener.OnGetApproveDetailListener;
import com.aurora.oa.listener.OnRequestHttpDataListener;
import com.aurora.oa.model.RequestHttpModel;
import com.aurora.oa.model.RequestHttpModelImpl;
import com.aurora.oa.work.bean.ApproveDataBean;
import com.aurora.oa.work.view.ApproveDetailActivityView;
import com.google.gson.Gson;


/**
* Created by Administrator on 2017/04/25
*/

public class ApproveDetailActivityPresenterImpl implements ApproveDetailActivityPresenter{
    ApproveDetailActivityView view;
    RequestHttpModel model = new RequestHttpModelImpl();

    public ApproveDetailActivityPresenterImpl(ApproveDetailActivityView view){
        this.view = view;
    }


    @Override
    public void displayApproveData(String approveId) {
        model.getApproveDetail(approveId, new OnGetApproveDetailListener() {
            @Override
            public void onGetApproveDetailSuccess(ApproveDataBean approveDataBean) {
                view.displayApproveData(approveDataBean);
            }

            @Override
            public void onGetApproveDetailFail(String message) {
                view.onGetApproveDataError(message);
            }
        });

    }

    @Override
    public void doTransfer(String id, String transferIds) {
        model.doApproveTransfer(id,transferIds, new OnRequestHttpDataListener() {
            @Override
            public void onRequestDataSuccess(String body) {

                Gson gson = new Gson();
               HttpResult result = gson.fromJson(body,HttpResult.class);
                if(result.success){
                    view.optionSuccess(result.msg);
                }else{
                    view.optionFail(result.msg);
                }

            }

            @Override
            public void onRequestDataFail(String message) {
                view.optionFail(message);
            }
        });
    }

    @Override
    public void doAgree(String id) {
        model.doApproveAgree(id,2, new OnRequestHttpDataListener() {
            @Override
            public void onRequestDataSuccess(String body) {

                Gson gson = new Gson();
                HttpResult result = gson.fromJson(body,HttpResult.class);
                if(result.success){
                    view.optionSuccess(result.msg);
                }else{
                    view.optionFail(result.msg);
                }
            }

            @Override
            public void onRequestDataFail(String message) {
                view.optionFail(message);
            }
        });
    }

    @Override
    public void doDeni(String id) {
        model.doApproveDeni(id,3, new OnRequestHttpDataListener() {
            @Override
            public void onRequestDataSuccess(String body) {

                Gson gson = new Gson();
                HttpResult result = gson.fromJson(body,HttpResult.class);
                if(result.success){
                    view.optionSuccess(result.msg);
                }else{
                    view.optionFail(result.msg);
                }

            }

            @Override
            public void onRequestDataFail(String message) {
                view.optionFail(message);
            }
        });
    }

    @Override
    public void doComment(String id, String content) {
        model.doApproveComment(id,content, new OnRequestHttpDataListener() {
            @Override
            public void onRequestDataSuccess(String body) {

                Gson gson = new Gson();
                HttpResult result = gson.fromJson(body,HttpResult.class);
                if(result.success){
                    view.showMessage(result.msg);
                }else{
                    view.optionFail(result.msg);
                }

            }

            @Override
            public void onRequestDataFail(String message) {
                view.optionFail(message);
            }
        });
    }
}